import { shopPath,baseURL } from '@/utils/config.js'

// 判断是否在手机微信内浏览器
export function isWechat() {
    // return /MicroMessenger/i.test(window.navigator.userAgent);
	return true
}

// object 转 querystring
export function objectToQuerystring(params){
	return Object.keys(params).map(key => key + "=" + params[key]).join("&");
}

// 获取当前路由
export function getCurrRoute() {
	const routes = getCurrentPages(); // 获取当前打开过的页面路由数组
	const curPage = routes[routes.length - 1]
	const curRoute = curPage.route //获取当前页面路由
	const qs = curPage.options || curPage.$route.query
	
	const str = objectToQuerystring(qs)
	
	return `/${curRoute}?${str}`
}

/**
 * 是否在数组内
 */
export const inArray = (search, array) => {
  for (var i in array) {
    if (array[i] == search) return true
  }
  return false
}

/**
 * 判断是否为空对象
 * @param {*} object 源对象
 */
export const isEmptyObject = (object) => {
  return Object.keys(object).length === 0
}

/**
 * 判断是否为空
 * @param {*} object 源对象
 */
export const isEmpty = (value) => {
  if (isArray(value)) {
    return value.length === 0
  }
  if (isObject(value)) {
    return isEmptyObject(value)
  }
  return !value
}

/**
 * 判断是否为数组
 * @param {*} array
 */
export const isArray = (array) => {
  return Object.prototype.toString.call(array) === '[object Array]'
}

/**
 * 判断是否为对象
 * @param {*} object
 */
export const isObject = (object) => {
  return Object.prototype.toString.call(object) === '[object Object]'
}

// 获取商城url地址
export const getMeixingUrl = () => {
	//const { protocol, host } = window.location
	const pathname = baseURL + shopPath
	return pathname
}